package com.elitel.common.businessJdbc.postgre;

import com.elitel.common.businessJdbc.BusinessScriptPreparedStatement;


public class PostgreSQLScriptPreparedStatement extends BusinessScriptPreparedStatement{

    @Override
    public String getPrecompileSql() {
        StringBuilder sb = new StringBuilder();
        sb.append("select a.* from ( ")
                .append(getSqlWithPlaceHolder())
                .append(" ) a");
        if(isPageable()){
            sb.append(containPageableSqlSection());
        }

        return sb.toString();
    }

    public String containPageableSqlSection() {
        StringBuilder sb = new StringBuilder();
        sb.append(" LIMIT ")
                .append(getPageSize())
                .append(" OFFSET ")
                .append(getPageSize() * (getPageNumber() - 1));
        return sb.toString();
    }

}
